package com.kafka.study.consumer;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class DeadConsumer {
    @Resource(name = "deadKafkaTemplate")
    private KafkaTemplate<String, String> kafkaTemplate;

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @KafkaListener(topics = "${spring.kafka.template.dead-topic}",
            containerFactory = "deadKafkaListenerContainer")
    public void deadListener(ConsumerRecord<String, String> record) {
        try {
            log.error("received dead message, key={}, value={}", record.key(), record.value());
        } catch (Exception ex) {
            log.error("something wrong");
        }
    }
}
